<?php
// app/controller/Crawler.php
namespace app\controller\wow;

use app\FrontendController;
use app\model\wow\WupinModel;
use think\facade\Request;
use think\facade\Db;

use app\model\wow\GoldPriceModel;

/**
 * 该控制器为金价的相关信息
 */
class Gold extends FrontendController
{

    /**
     * 金价统计
     * 访问链接：https://tp.x-mii.com/wow.gold/tongji
     */
    public function tongji( Request $request ){

        $_GPC = Request::param(  );
        $today = time();

        if( empty( $_GPC['start'] ) ){
            $lastMoth = strtotime('-1 month', $today);
            $startDay = date('Y-m-d', $lastMoth);
        }else{
            $startDay = $_GPC['start'];
        }


        $lmList = GoldPriceModel::where( 'create_time', '>=', $startDay )
            ->where( 'faction', '=', 'alliance')
            ->order('create_time','asc')
            ->select();

        $blList = GoldPriceModel::where( 'create_time', '>=', $startDay )
            ->where( 'faction', '=', 'tribe')
            ->order('create_time','asc')
            ->select();

        // return $lmList;
        return json([
            'alliance'  => $lmList,
            'tribe'     => $blList,
        ]);

        
    }


}